<template>
  <div>
    <badge :count="count"></badge>
  </div>
</template>

<script>
  import Badge from '@/components/Badge'
  import { getShopCart } from '@/api/shop'

  export default {
    components: { Badge },
    data() {
      return {
        isComponents: true,
        count: 0,
        listQuery: {}
      }
    },
    onShow() {
      this.initCount()
    },
    mounted() {
      // 初始化data
      Object.assign(this.$data, this.$options.data())
      this.initCount()
    },
    methods: {
      initCount() {
        if (!this.getCustomerId) return
        this.listQuery.memberId = this.getShowBuyCard ? this.getCustomerId : this.getMemberId
        this.listQuery.customerId = this.getShowBuyCard ? this.getCustomerId : this.getMemberId
        getShopCart(this.listQuery).then(response => {
          if (response.isError) return
          this.count = response.data.effectiveList.length
        }).catch(() => {
        })
      }
    }
  }
</script>

<style scoped>

</style>
